package org.example;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Action;

@Configuration
public class RabbitMQConfig {

    //交换机  Exchange
    @Bean // id = directExchange
    public DirectExchange directExchange() {
        return new DirectExchange("test_exchange", true, false);
    }

    //队列
    @Bean //id = queue
    public Queue testQueue1() {
        return new Queue("test_queue1");
    }

    @Bean //id = queue
    public Queue testQueue2() {
        return new Queue("test_queue2");
    }
    @Bean //id = queue
    public Queue testQueue3() {
        return new Queue("test_queue3");
    }
    //绑定 交换机 和队列 test_queue1
    @Bean
    public Binding binding(
            @Autowired Queue testQueue1,
            @Autowired DirectExchange directExchange) {
        return BindingBuilder.bind(testQueue1).to(directExchange).with("test_direct");
    }

    //绑定 交换机 和队列 test_queue2
    @Bean
    public Binding binding2(
            @Autowired Queue testQueue2,
            @Autowired DirectExchange directExchange) {

        return BindingBuilder.bind(testQueue2).to(directExchange).with("test_direct");
    }

    @Bean
    public Binding binding3(
            @Autowired Queue testQueue3,
            @Autowired DirectExchange directExchange) {
        return BindingBuilder.bind(testQueue3).to(directExchange).with("test_direct");
    }
}
